package com.itrip.auth.service;

import com.itrip.utils.RedisAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class MailService {

    @Autowired
    private JavaMailSender javaMailSender;
    @Autowired
    private RedisAPI redisAPI;

    public void send(String to,String subject,String content,String code){
        SimpleMailMessage mail = new SimpleMailMessage();
        mail.setFrom("1877575733@qq.com");
        mail.setTo(to);
        mail.setSubject(subject);
        mail.setText(content);
        javaMailSender.send(mail);
        redisAPI.setex(to,5*60,code);
    }

    public String getCode(String key){
        return redisAPI.get(key);
    }
}
